package impl.service;

import entity.User;
import entity.User_Sex;
import face.dao.IUserDao;
import face.service.IUserService;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.function.Consumer;


/**
 * @author futao
 * Created on 2018/2/5 - 18:59.
 */
@Service
@Transactional(timeout = 2000, isolation = Isolation.REPEATABLE_READ)
public class UserServiceImpl implements IUserService {
    @Resource
    private SessionFactory sessionFactory;
    @Resource
    private IUserDao userDao;

    @Override
    public void add() {
        Session currentSession = sessionFactory.getCurrentSession();
        User user = new User();
        user.setNickName("付韬");
        user.setSex(User_Sex.Man);
        user.setMobile("187978119921879781199218797811992187978119921879781199218797811992");
        user.setQQ("1185172056");
        currentSession.save(user);
    }

    @Override
    public void list() {
        List<User> list = userDao.list();
        list.forEach(System.out::println);
    }
}
